from PyQt4 import QtGui, QtCore

import cv
import gameframe


def drawBorder(src, color):
    
    pmap = QtGui.QPixmap(src)
    painter = QtGui.QPainter()
    pen = QtGui.QPen()
    pen.setColor(QtGui.QColor(color))
    pen.setWidth(5)
    painter.begin(pmap)
    painter.setPen(pen)
    w,h = src.size().width()-3, src.size().height()-3
    painter.drawRect(QtCore.QRect(1,1,w,h))
    return pmap
    
def mat_to_qimage(src):
    
    qimage = QtGui.QImage(src.cols, src.rows, QtGui.QImage.Format_ARGB32)
    
    [qimage.setPixel(x, y, QtGui.qRgb(src[y,x][2], src[y,x][1], src[y,x][0]))
     for x in xrange(src.cols)
     for y in xrange(src.rows)]
    
    return qimage

def mk_pressStartPmap(w,h):
    alpha = QtGui.QImage('data/alpha3.png').scaled(w,h)
    pmap = QtGui.QPixmap(alpha)
    painter = QtGui.QPainter()
    painter.begin(pmap)
    pen = QtGui.QPen()
    pen.setColor(QtGui.QColor('white'))
    painter.setPen(pen)
    painter.setFont(QtGui.QFont('sans',52))
    painter.drawText(250,310,QtCore.QString('Press Start'))
    painter.drawText(250,410,QtCore.QString('  to begin'))
    return pmap

def mk_countDown(w,h,n):
    alpha = QtGui.QImage('data/alpha%s.png' % str(n)).scaled(w,h)
    pmap = QtGui.QPixmap(alpha)
    painter = QtGui.QPainter()
    painter.begin(pmap)
    pen = QtGui.QPen()
    pen.setColor(QtGui.QColor('white'))
    painter.setPen(pen)
    painter.setFont(QtGui.QFont('sans',52))
    painter.drawText(250,310,QtCore.QString('Starting in'))
    painter.drawText(410,410,QtCore.QString('%s' % str(n)))
    return pmap

def mk_lose(w,h):
    alpha = QtGui.QImage('data/alpha2.png').scaled(w,h)
    pmap = QtGui.QPixmap(alpha)
    painter = QtGui.QPainter()
    painter.begin(pmap)
    pen = QtGui.QPen()
    pen.setColor(QtGui.QColor('white'))
    painter.setPen(pen)
    painter.setFont(QtGui.QFont('sans',52))
    painter.drawText(190,360,QtCore.QString('Sorry, you lost!'))
    return pmap

def mk_win(w,h):
    alpha = QtGui.QImage('data/alpha2.png').scaled(w,h)
    pmap = QtGui.QPixmap(alpha)
    painter = QtGui.QPainter()
    painter.begin(pmap)
    pen = QtGui.QPen()
    pen.setColor(QtGui.QColor('white'))
    painter.setPen(pen)
    painter.setFont(QtGui.QFont('sans',52))
    painter.drawText(300,360,QtCore.QString('You Won!'))
    return pmap